//////////////////////////预案匹配//////////////
var resYAPPArray = new Array();
var DDSBResArray = new Array();
var matchObj = null;
//点击查询之后的函数
function queryYAPP(){
	var region =$("#YAPPShen").val();
	if($("#YAPPXian").val()!="-1"){
		region = $("#YAPPXian").val();
	}else if($("#YAPPShi").val()!="-1"){
		region = $("#YAPPShi").val();
	}
	var zhlx = $("#YAPPZHLX").val();
	var gm = $("#YAPPGM").val();
	var xqdj = $("#YAPPZQDJ").val();
	var wxrk = $("#YAPPWXRK").val();
	var wxcc = $("#YAPPWXCC").val();
	var data = {
		"region":region,
		"zhlx" :zhlx,
		"gm" :gm,
		"xqdj" :xqdj,
		"wxrk" :wxrk,
		"wxcc" :wxcc
	}
	var url = "queryFzyaList.shtml";
	$('#YAPP_table').datagrid({
				url : url,
				queryParams : data,
				onLoadSuccess : function(res) {
					//$("#region").attr("value",res.selects[0]);
				},
				onLoadError : function(res) {
					alert("查询失败!");
				}
			});
	
}

//初始化table
function initYappTable(){
	$("#YAPP_table").datagrid({
		striped : true,
		pageSize : 10,
		height : 315,
		nowrap : false,
		columns : [[ {
					field : '1_jbqk0110',
					title : '灾害点名称',
					width : 120,
					align : 'center',
					editor : 'text'
				},{
					field : '1_jbqk0102',
					title : '灾害点标识',
					width : 80,
					align : 'center',
					formatter : function(value, rec, rowIndex) {// value id rec
						// 该对象
						//curRecObj = rec;
						var type = top.getOperTypeZhdByCode(rec[1].id.jbqk0102);
						var resutsHTML = "<div style='align:center;'>"
								+type
								+"</div>";
						return resutsHTML;
					}
				},{
					field : '0_fzya03170',
					title : '地理位置',
					width : 180,
					align : 'center',
					editor : 'text'
				},{
					field : '0_fzya03190',
					title : '规模',
					width : 50,
					align : 'center',
					editor : 'text'
				},{
					field : '0_fzya03200',
					title : '威胁人口',
					width : 60,
					align : 'center',
					editor : 'text'
				},{
					field : '0_fzya03210',
					title : '威胁财产',
					width : 60,
					align : 'center',
					editor : 'text'
				},{
					field : '0_fzya03220',
					title : '险情等级',
					width : 60,
					align : 'center',
					editor : 'text'
				},{
					field : '0_fzya03280',
					title : '潜在危害',
					width : 120,
					align : 'center',
					editor : 'text'
				},{
					field : 'oper',
					title : '操作',
					width : 80,
					align : 'center',
					formatter : function(value, rec, rowIndex) {// value id rec
						// 该对象
						//curRecObj = rec;
					
						resYAPPArray.push(rec);
						var num = resYAPPArray.length-1;
						var resutsHTML = "";
						var resutsHTML = "<div style='align:center;'>"
								+ "<a name='showDetails' style='padding:5px;cursor:pointer;text-decoration: underline;' onclick='showYAPPDetails(\""
								+ num
								+ "\",false)'>详情</a>"
								+ "<a name='addLink' style='padding:5px;cursor:pointer;text-decoration: underline;' onclick='showYAPPDetails(\""
								+ num
								+ "\",true)'>匹配</a>"
								+"</div>";
						return resutsHTML;
					}
				}]],
		pagination : true,
		rownumbers : true,
		singleSelect : true,
	});
}

//点击操作栏里面的详情或者编辑，调用的方法
function showYAPPDetails(initPid,isEdit){
	var curRecObj = resYAPPArray[initPid][0];
	var isReadOnly = "readOnly";
	var isDisabled = "disabled";
	var isDisPlay = "none";
	if(isEdit){
		if(matchObj==null){//未选定要匹配的点
			alert("请先选择要匹配的上报点");
			$('#tabyjtxdiv').tabs("select","匹配点选定");
			return;
		}
		isReadOnly = "";
		isDisabled = "";
		isDisPlay = "";
		$("#matchDiv").css("display","");
		///匹配点信息填充
		$("#yjcz12010").attr("value",matchObj.yjcz12010).attr("readOnly","readOnly").attr("disabled","disabled");
		$("#yjcz12020").attr("value",matchObj.yjcz12020).attr("readOnly","readOnly").attr("disabled","disabled");
		$("#yjcz12060").attr("value",matchObj.yjcz12060).attr("readOnly","readOnly").attr("disabled","isDisabled");
		$("#fzya03000").attr("value",matchObj.yjcz12000).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	}
	var time = curRecObj.fzya03230==null?"":curRecObj.fzya03230;
	time=time.replace("T"," ");
	//eTime=eTime.replace("T"," ");
	//$("#yjcz10000").attr("value",curRecObj.yjcz10000);
	//$("#yjcz10005").attr("value",curRecObj.yjcz10005);
	//$("input[type=radio][name=yjcz10010][value="+curRecObj.yjcz10010+"]").attr("checked","checked");
	//$("#yjcz10010").attr("value",curRecObj.yjcz10010).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	time = time==""?matchObj.yjcz12010.replace("T"," "):time;
	$("#fzya03160").attr("value",curRecObj.fzya03160).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	//$("#yjcz10030").attr("value",sTime).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	//$("#yjcz10040").attr("value",eTime).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#fzya03170").attr("value",curRecObj.fzya03170).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#fzya03180").attr("value",curRecObj.fzya03180).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#fzya03190").attr("value",curRecObj.fzya03190).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#fzya03200").attr("value",curRecObj.fzya03200).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#fzya03210").attr("value",curRecObj.fzya03210).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#fzya03220").attr("value",curRecObj.fzya03220).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#fzya03230").attr("value",time).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#fzya03240").attr("value",curRecObj.fzya03240).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#fzya03250").attr("value",curRecObj.fzya03250).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#fzya03260").attr("value",curRecObj.fzya03260).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#fzya03270").attr("value",curRecObj.fzya03270).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#fzya03280").attr("value",curRecObj.fzya03280).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#fzya03290").attr("value",curRecObj.fzya03290).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#fzya03300").attr("value",curRecObj.fzya03300).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#fzya03310").attr("value",curRecObj.fzya03310).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#fzya03320").attr("value",curRecObj.fzya03320).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#fzya03330").attr("value",curRecObj.fzya03330).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#fzya03340").attr("value",curRecObj.fzya03340).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#fzya03350").attr("value",curRecObj.fzya03350).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#fzya03360").attr("value",curRecObj.fzya03360).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#fzya03370").attr("value",curRecObj.fzya03370).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#fzya03380").attr("value",curRecObj.fzya03380).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#fzya03390").attr("value",curRecObj.fzya03390).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#fzya03400").attr("value",curRecObj.fzya03400).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#fzya03410").attr("value",curRecObj.fzya03410).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#fzya03420").attr("value",curRecObj.fzya03420).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#fzya03430").attr("value",curRecObj.fzya03430).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#fzya03440").attr("value",curRecObj.fzya03440).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#fzya03490").attr("value",curRecObj.fzya03490).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	
	$("#submitBtn_yapp").css("display",isDisPlay);
	$("#resetBtn_yapp").css("display",isDisPlay);
	$("#detailsDialog_yaxx").dialog('open');
}
////////////////////匹配操作
//查询单点上报数据表
function queryDDSB_Fzjc(){
	var sheng = $("#ypxxsbShen").val();
	var shi = $("#ypxxsbShi").val();
	var xian = $("#ypxxsbXian").val();
	var zhlx = $("#ypxxsbZHLX").val();
	var areaCode = handlerAreaFunc(shen,shi,xian);
	var zhCode = "";
	if(zhlx==""){
		zhCode = handlerZhCodeFunc(areaCode);
	}else{
		zhCode = handlerZhCodeFunc(areaCode,zhlx);
	}
	var startTime = $("#ypxxsbStartTime").val();
	var endTime = $("#ypxxsbEndTime").val();
	var url = "queryDDSB.shtml";
	var data = {
		"startTime":startTime,
		"endTime":endTime,
		"zhCode":zhCode,
		"qType":"yapp"
	};
	DDSBResArray = [];
	$("#ypxxsb_tableFZJC").datagrid({
		url : url,
		queryParams : data,
		onLoadError : function(res) {
			alert("查询失败!");
		},
		onLoadSuccess : function(res) {
			addMarkForDDSB();
		}
	});
}

function initYpxxSbTable(){
	$("#ypxxsb_tableFZJC").datagrid({
		url:"",
		striped : true,
		pageSize : 10,
		height : 315,
		nowrap : false,
		columns : [[ {
					field : 'yjcz12010',
					title : '预报时间',
					width : 180,
					align : 'center',
					editor : 'text'
				},{
					field : 'yjcz12020',
					title : '地理位置',
					width : 150,
					align : 'center',
					editor : 'text'
				},{
					field : 'yjcz12060',
					title : '上报记录',
					width : 150,
					align : 'center',
					editor : 'text'
				},{
					field : 'yjcz12080',
					title : '多媒体记录',
					width : 120,
					align : 'center',
					editor : 'text',
					formatter : function(value, rec, rowIndex) {// value id rec
						// 该对象
						//curRecObj = rec;
						var num = DDSBResArray.length;
						var resutsHTML = "";
						var resutsHTML = "<div style='align:center;'>"
								+ "<a name='showDetails' style='padding:5px;cursor:pointer;text-decoration: underline;' onclick='playVadio(\""
								+ rec.yjcz12080
								+ "\")'>播放</a>"
								+"</div>";
						return resutsHTML;
					}
				},{
					field : 'oper',
					title : '操作',
					width : 120,
					align : 'center',
					formatter : function(value, rec, rowIndex) {// value id rec
						// 该对象
						//curRecObj = rec;
						DDSBResArray.push(rec);
						var num = DDSBResArray.length-1;
						var resutsHTML = "";
						var resutsHTML = "<div style='align:center;'>"
								+ "<a name='showDetails' style='padding:5px;cursor:pointer;text-decoration: underline;' onclick='selectToMatch(\""
								+ num
								+ "\")'>选定匹配</a>"
								+"</div>";
						return resutsHTML;
					}
				}]],
		pagination : true,
		rownumbers : true,
		singleSelect : true,
	});
}
//选定没有预案的上报点
function selectToMatch(num){
	matchObj = DDSBResArray[num];
	alert("选定成功");
}
//点击播放mp3
function playVadio(fileName){
	if(fileName==null)
		fileName=matchObj.yjcz12080;
	window.open("../filePlay.jsp?url="+fileName);
}
function addFzya(){
	var url = "../../updateFzya03TempById.shtml";
	var dataObj = {
		"fzya03000":$("#fzya03000").val(),
		"fzya03160":$("#fzya03160").val(),
		"fzya03170":$("#fzya03170").val(),
		"fzya03170":$("#fzya03170").val(),
		"fzya03190":$("#fzya03190").val(),
		"fzya03200":$("#fzya03200").val(),
		"fzya03210":$("#fzya03210").val(),
		"fzya03220":$("#fzya03220").val(),
		"fzya03230":$("#fzya03230").val(),
		"fzya03240":$("#fzya03240").val(),
		"fzya03250":$("#fzya03250").val(),
		"fzya03260":$("#fzya03260").val(),
		"fzya03270":$("#fzya03270").val(),
		"fzya03280":$("#fzya03280").val(),
		"fzya03290":$("#fzya03290").val(),
		"fzya03300":$("#fzya03300").val(),
		"fzya03310":$("#fzya03310").val(),
		"fzya03320":$("#fzya03320").val(),
		"fzya03330":$("#fzya03330").val(),
		"fzya03340":$("#fzya03340").val(),
		"fzya03350":$("#fzya03350").val(),
		"fzya03360":$("#fzya03360").val(),
		"fzya03370":$("#fzya03370").val(),
		"fzya03380":$("#fzya03380").val(),
		"fzya03390":$("#fzya03390").val(),
		"fzya03400":$("#fzya03400").val(),
		"fzya03410":$("#fzya03410").val(),
		"fzya03420":$("#fzya03420").val(),
		"fzya03430":$("#fzya03430").val(),
		"fzya03440":$("#fzya03440").val(),
		"fzya03490":$("#fzya03490").val(),
	}
	var data = JSON.stringify(dataObj);
	//alert(data);
	$.post(url,{"fzya03Temp":data}, addFzyaResult);
}
function addFzyaResult(res){
	if(res){
		alert("更新成功");
		$('#yapp_tableFZJC').datagrid('reload');
	}else{
		alert("更新失败");
	}
		
	$("#detailsDialog_yaxx").dialog('close');
}